<!DOCTYPE html>
  <html>
  <head>
    <link rel="stylesheet" type="text/css" href="/static/plugin/layui/css/layui.css"> 
  </head>
  <body>
    <div style="text-align:center; font-size:25px; padding:20px;"> 添加项目 </div>
    <div style="width:20%;margin:0 auto; border:2px solid #eee; padding:10px;">
      <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">游戏名称</label>
        <div class="layui-input-inline">
          <input type="text" name="game_name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">版本名称</label>
        <div class="layui-input-inline">
          <input type="text" name="server_type" required  lay-verify="required" placeholder="请输入版本名称" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">数据库</label>
        <div class="layui-input-inline">
          <input type="text" name="database" required lay-verify="required" placeholder="请输入数据库" autocomplete="off" class="layui-input">
        </div>
      </div>
       <div class="layui-form-item">
        <label class="layui-form-label">IP</label>
        <div class="layui-input-inline">
          <input type="text" name="ip" required lay-verify="required" placeholder="请输入IP" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">端口</label>
        <div class="layui-input-inline">
          <input type="text" name="port" required lay-verify="required" placeholder="请输入端口" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <a class="layui-btn submit">立即提交</a>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>
    
    <script src="/static/plugin/layui/layui.js"> </script> 
    <script src="/static/js/jquery.js"> </script> 

    <script>
      layui.use('form', function(){

        $(".submit").on("click",function(){
          var form = layui.form;
       
          var game_name = $("input[name='game_name']").val();
          var server_type = $("input[name='server_type']").val();
          var database = $("input[name='database']").val();
          var ip = $("input[name='ip']").val();
          var port = $("input[name='port']").val();
          
          if(game_name == ""){
            layer.msg("游戏不能为空");
            return false;
          }
          if(server_type == ""){
            layer.msg("项目不能为空");
            return false; 
          }
          if(database == ""){
            layer.msg("数据库不能为空");
            return false; 
          }
          if(ip == ""){
            layer.msg("IP不能为空");
            return false;
          }

          if(port == ""){
            layer.msg("端口不能为空");
            return false;
          }

          $.post(
            "/add_user", 
            {
              "game_name": game_name,
              "server_type": server_type, 
              "database": database,
              "ip": ip,
              "port": port
            },
            function(data){
              layer.msg(data.Date)
            }
          ) 
        })
      });
    </script>
    </div>
  </body>
</html> 